function [G1,G2,result,result_LS_code_base,result_LS_code_rover]=calc_preprocessing_phase(RNX_header_base, RNX_data_base, RNX_header_rover, RNX_data_rover, NAV_header, NAV_data, X0_base, epoch, options)
%% function [G1,G2,result,result_LS_code_base,result_LS_code_rover]=calc_preprocessing_phase(RNX_header_base, RNX_data_base, RNX_header_rover, RNX_data_rover, NAV_header, NAV_data, X0_base, epoch, options)
%% Data organization and preparation before phase processing - interface of calc_preprocessing for phase preprocessing
%%
%% Beilin Jacques - ENSG/DPTS - 2011-12-18
%% Clement Fontaine - 2013-12-17
%%
%% Input
%%	- RNX_header_base, RNX_data_base : obs rinex data generated by function load_rinex_o
%%       If spp : set RNX_header_base and RNX_data_base to an empty structure
%%	- RNX_header_rover, RNX_data_rover : obs rinex data generated by function load_rinex_o
%%  - NAV_header,NAV_data : nav data (rinex_n or sp3) generated by load_rinex_n (for broadcasted ephemeris) or load_sp3 (for precise orbits)
%% 		- broadcasted ephemeris : NAV_header,NAV_data generated from broadcasted ephemeris .n or .p
%% 		- precise orbits : replace NAV_header,NAV_data by sp3_header,sp3_data, and set options.nav to 'sp3'
%% - X0_base : base receiver position
%%	- epoch : computation epoch
%%	- options : structure containing processing options ( optional )
%% {
%%   X0 : approximated coordinates (column vector of 6 elements [X;Y;Y;cdtr;cGGTO;cGPGL]) 
%%        default : X0 = [0 ;0; 0; 0; 0; 0];
%%   const : constellations used ('G' = GPS, 'R' = Glonass, 'E' = Galileo, for multi-constellation concatenate chars)
%%        default : 'G'
%%   nav : type of orbits
%%		   - 'brdc' : broadcasted ephemeris
%%         - 'sp3' : precise orbits
%%         default : 'brdc'    
%%   cut_off : elevation cut off in degree
%%         default : 3 degrees
%% }
%%
%% Computation with iono-free combination 
%%
%% Output
%% - G : cell tab (G1 = base, G2 = rover)
%%   nb_constellation * 32 lines, 8 columns
%%   column 1 : constellation
%%   column 2 : PRN
%%   column 3 : mjd (set to 0 if no satellite)
%%   column 4 : Code 1
%%   column 5 : Code 2
%%   column 6 : Iono-free combination with code observation
%%   column 7 : Phase 1
%%   column 8 : Phase 2
%%   column 9 : Iono-free combination with phase observation
%%   column 10 : Ephemeris of this satellite at mjd (if sp3, Eph.mjd set to 1)
%%   column 11 : structure containing intermediary results
%%      {
%%        PR =  21340831.1682333               : Code corrected by dte, TGD and dtrelat (m)
%%        PRC1 =  21001056.4770000             : Initial C1 code
%%        PRC2 =  21001061.9650000             : Initial C2 code
%%        PRC3 =  21001048.0735000             : Initial iono-free combination on code
%%        PhaseL1 =  21001066.9963885          : Initial L1 phase
%%        PhaseL2 =  21001079.5890304          : Initial L2 phase
%%        PhaseL3 =  21001047.7139056          : Initial iono-free combination on phase
%%        PR0 =  21331256.8538257              : Initial code (m)
%%        tr =  56442.9996527778               : reception time (mjd)
%%        travel_time =  0.0711534139188574    : travel time (mjd)
%%        te =  56442.9996519543               : emission time (mjd)
%%        dtrelat = -3.10256072047897e-09       : relativist correction (s)
%%        TGD = 0                              : TGD (s)
%%        dte =  3.19395777860622e-05          : satellite clock error (s)
%%        te_corr =  56442.9996519539          : corrected emission time (mjd) 
%%        Xs =  13482112.5310270               |
%%        Ys = -12886016.8650971               | : satellite position at te (m)
%%        Zs =  18861799.1754938               |
%%        Az =  4.91239303897012               : satellite azimuth (rad)
%%        Ele =  0.870337539193024             : satellite elevation (rad)
%%        h =  160.461182295345                : satellite elevation (m)
%%        dtropo =  3.04510732151988           : tropospheric correction (m)
%%        diono = 0                            : ionospheric correction (m)
%%        PR_corr =  21340828.1231260          : corrected pseudo-range (m)
%%        Xsr =  13482045.8232355              |
%%        Ysr = -12886086.6583699              | : satellite position at te, with rotation correction (m)
%%        Zsr =  18861799.1754938              |
%%      }
%% - result : structure containing final results
%%    {
%%      t =                                    : gpstime time structure
%%      {
%%        s1970 =  1369872000
%%        mjd =  56442
%%        jd =  2456442.50000000
%%        jd50 =  23160
%%        wk =  1742
%%        wsec =  345600
%%        yyyy =  2013
%%        yy =  13
%%        mon =  5
%%        dd =  30
%%        hh = 0
%%        min = 0
%%        sec = 0
%%        doy =  150
%%        wd =  4
%%        dsec = 0
%%        dy =  2013.40793976728
%%        GMST =  16.5112396504555
%%        EQEQ =  1.93995502140448e-04
%%        GAST =  16.5114336459577
%%      }
%%    
%%
%%
%%      PosSat =                               : satellite positions [Xs_base Ys_base Zs_base Xs_rover Ys_rover Zs_rover]
%%    
%%         11444831.05221041   19872840.57973917   13728071.85325433  11444831.05221041   19872840.57973917   13728071.85325433
%%         21785914.68839299  -14994024.60020332   -2170721.88255118  21785914.68839299  -14994024.60020332   -2170721.88255118
%%          3212056.70511915   16183670.97379925   20991792.25531062   3212056.70511915   16183670.97379925   20991792.25531062
%%         24942174.32843519   -6388801.36023886    5402212.53356499  24942174.32843519   -6388801.36023886    5402212.53356499
%%    
%%      Dobs =                                 : corrected pseudo-ranges [base rover]
%%    
%%         22802832.7032533 22802832.7032533
%%         24249925.7279791 24249925.7279791
%%         22795477.1178442 22795477.1178442
%%         21767854.7426687 21767854.7426687
%%    
%%      DobsC1 =                                 : C1 [base rover]
%%    
%%         22802832.7032533 22802832.7032533
%%         24249925.7279791 24249925.7279791
%%         22795477.1178442 22795477.1178442
%%         21767854.7426687 21767854.7426687
%%
%%      DobsC2 =                                 : C2 [base rover]
%%    
%%         22802832.7032533 22802832.7032533
%%         24249925.7279791 24249925.7279791
%%         22795477.1178442 22795477.1178442
%%         21767854.7426687 21767854.7426687
%%
%%      DobsC3 =                                 : C3 [base rover]
%%    
%%         22802832.7032533 22802832.7032533
%%         24249925.7279791 24249925.7279791
%%         22795477.1178442 22795477.1178442
%%         21767854.7426687 21767854.7426687
%%
%%      PobsL1 =                               : L1 obs [base rover]
%%     
%%         21379867.5080223 22802832.7032533 
%%         22483230.1784891 24249925.7279791
%%         23821262.8009240 22795477.1178442
%%         20239064.0619077 21767854.7426687
%%
%%      PobsL2 =                               : L2 obs [base rover]
%%     
%%         21379867.5080223 22802832.7032533
%%         22483230.1784891 24249925.7279791
%%         23821262.8009240 22795477.1178442
%%         20239064.0619077 21767854.7426687
%%
%%      PobsL2 =                               : L2 obs [base rover]
%%     
%%         21379867.5080223 22802832.7032533
%%         22483230.1784891 24249925.7279791
%%         23821262.8009240 22795477.1178442
%%         20239064.0619077 21767854.7426687
%%    
%%      sat_index =                            : satellite id ['constPRN',index in G] constPRN : Format A1I2
%%      
%%        {
%%          [1,1] = G14
%%          [2,1] = G20
%%          [3,1] = G22
%%          [4,1] = G32
%%          [1,2] =  14
%%          [2,2] =  20
%%          [3,2] =  22
%%          [4,2] =  32
%%        }
%%      
%%    
%%      ElevSat =                              : satellite elevation (rad) [base rover]
%%    
%%         0.558558791057047 0.558558791057047
%%         0.244832779752556 0.244832779752556
%%         0.555984102770661 0.555984102770661
%%         0.693238540918065 0.693238540918065
%%
%%      AzSat =                                : satellite azimuth (rad) [base rover]
%%    
%%         0.558558791057047 0.558558791057047
%%         0.244832779752556 0.244832779752556
%%         0.555984102770661 0.555984102770661
%%         0.693238540918065 0.693238540918065
%%
%%      Dtropo =                               : tropospheric delay correction (m) [base rover]
%%          
%%         3.08312899894975 3.08312899894975
%%         4.19965813067309 4.19965813067309 
%%         6.73638267466045 6.73638267466045  
%%         2.47054186459352 2.47054186459352 
%%    
%%      nb_GPS =  5                            : number of present GPS satellites at mjd
%%      nb_GLO = 0                             : number of present Glonass satellites at mjd
%%      nb_GAL = 0                             : number of present Galileo satellites at mjd
%%      nb_GPS_calc =  4                       : number of present GPS satellites at mjd used in computation (after cut_off)
%%      nb_GLO_calc = 0                        : number of present Glonass satellites at mjd used in computation (after cut_off)
%%      nb_GAL_calc = 0                        : number of present Galileo satellites at mjd used in computation (after cut_off)
%%      nb_sat = 4                             : number of total present satellites at mjd used in computation (after cut_off)
%%    }
%%
%% - result_LS_code_base / result_LS_code rover : LS code estimation result structure. See calc_LS_code() for details
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

options.freq = 'iono_free';
options.iono = 'none';

[G1,G2,result,result_LS_code_base,result_LS_code_rover]=calc_preprocessing(RNX_header_base, RNX_data_base, RNX_header_rover, RNX_data_rover, NAV_header, NAV_data, X0_base, epoch, options);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

end
